package com.zizo.autohome.sta.slrank.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import com.zizo.util.ConnectionPool;

public class TableUtil {
	public final static void createtable() {
		Connection conn = ConnectionPool.getConnection("carvoice_biz", "localhost");
		String sql = "DROP TABLE IF EXISTS biz_slrank_bbs_temp;";
		String sqll = "DROP TABLE IF EXISTS biz_slrank_kb_temp;";
		String sql1 = "create table biz_slrank_bbs_temp like biz_slrank_bbs";
		String sql2 = "create table biz_slrank_kb_temp like biz_slrank_kb";
		Statement st = null;
		try {
			st = conn.createStatement();
			st.executeUpdate(sql);
			st.executeUpdate(sqll);
			st.executeUpdate(sql1);
			st.executeUpdate(sql2);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public final static void droptable() {
		Connection conn = ConnectionPool.getConnection("carvoice_biz", "localhost");
		String sql = "DROP TABLE IF EXISTS biz_slrank_bbs;";
		String sql1 = "DROP TABLE IF EXISTS biz_slrank_kb;";
		String sql2 = "ALTER TABLE biz_slrank_bbs_temp RENAME biz_slrank_bbs;";
		String sql3 = "ALTER TABLE biz_slrank_kb_temp RENAME biz_slrank_kb;";
		Statement st = null;
		try {
			st = conn.createStatement();
			st.executeUpdate(sql);
			st.executeUpdate(sql1);
			st.executeUpdate(sql2);
			st.executeUpdate(sql3);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
